//
//  RobCollectionCell.m
//  MyTrip
//
//  Created by zhang on 15/8/22.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "RobCollectionCell.h"
#import "UIImageView+WebCache.h"

@implementation RobCollectionCell


- (void)dealloc
{
    [_priceLabel release];
    [_discountImage release];
    [_discountLabel release];
    [_discountTitleLabel release];
    [super dealloc];
}



- (instancetype) initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.discountImage = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 55 * OffHeight)] autorelease];
        [self.contentView addSubview:_discountImage];
        
        self.discountTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _discountImage.frame.size.height, self.frame.size.width, 40 * OffHeight)];
        [_discountTitleLabel setBackgroundColor:[UIColor whiteColor]];
        [self.contentView addSubview:_discountTitleLabel];
        
        self.discountLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10 * OffWidth, _discountImage.frame.size.height + _discountTitleLabel.frame.size.height, 100 * OffWidth, 15 * OffHeight)] autorelease];
        [self.contentView addSubview:_discountLabel];
        
        self.priceLabel = [[[UILabel alloc] initWithFrame:CGRectMake(110 * OffWidth, _discountImage.frame.size.height + _discountTitleLabel.frame.size.height, self.frame.size.width - 100 * OffWidth, 15 * OffHeight)] autorelease];
        [self.contentView addSubview:_priceLabel];
        
    }
    return self;
}


- (void)cellSetValueWithDic:(NSDictionary *)dic{
    
#warning 缺少占位图
    [_discountImage sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"photo"]] placeholderImage:nil];
    [_discountTitleLabel setText:[dic objectForKey:@"title"]];
    _discountTitleLabel.numberOfLines = 2;
    _discountTitleLabel.font = [UIFont systemFontOfSize:13];
    [_discountLabel setText:[dic objectForKey:@"priceoff"]];
    _discountLabel.font = [UIFont systemFontOfSize:11];
    _discountLabel.textColor = [UIColor orangeColor];
    
    NSString *price = [dic objectForKey:@"price"];

    price = [price stringByReplacingOccurrencesOfString:@"<em>" withString:@""];
    price = [price stringByReplacingOccurrencesOfString:@"</em>" withString:@""];
    
    NSRange r = [price rangeOfString:@"元起"];
    NSRange aR = [price rangeOfString:price];
    NSRange nR = NSMakeRange(aR.location, aR.length - r.length);
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:price];
    [string addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} range:r];
    [string addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10]} range:r];
    
    [string addAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} range:nR];
    [string addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} range:nR];
    
    _priceLabel.attributedText = string;
    
}

















@end
